<template>
	<view>
		<!-- <view class="title-back">

		</view>
		<view class="title">
			<image class="left" @tap="back()" :src="$img('/static/2021-08-24/back-black.png')" mode="widthFix"></image>
			<view class="center">
				提交列表
			</view>
			<view class="right">
				完成
			</view>
		</view> -->
		<title-bar title="提交列表" :paddingNo="true" :type="user.is_end == 1?'wancheng_end':'wancheng'" @wancheng="user.wancheng()"></title-bar>
		<view class="tips">
			<image class="left" :src="$img('/static/2021-08-24/js3.png')" mode=""></image>
			<view class="right">
				点击通过表示确定找该好友.可选择多名好友，点击完成
				后.其它用户提交申请失效.活动结束。
			</view>
		</view>
		<view class="user-box">
			<view class="user" v-for="i,j in user.list" :key="i.id">
				<view class="left">
					<image class="left" :src="i.headImage" mode=""></image>
					<view class="right">
						<view class="top">
							<view class="left">
								{{i.nickname}}
							</view>
							<image class="right" v-if="i.sex == 1" :src="$img('/static/2021-08-24/nansheng.png')"
								mode=""></image>
							<image class="right" v-else :src="$img('/static/2021-08-24/nvsheng.png')" mode="">
							</image>

						</view>
						<view class="bottom">
							{{i.created_time}}
						</view>
					</view>
				</view>
				<view class="right" @click="user.pass(i.id)" v-if="i.is_pass != 1">
					通过
				</view>
				<view class="right" v-else>
					已通过
				</view>
			</view>
		</view>
		<view class="no-more-box">
			<view class="no-more-line">

			</view>
			<view class="no-more-text">
				没有更多了
			</view>
			<view class="no-more-line">

			</view>
		</view>
	</view>
</template>

<script>
	let $vue = null;
	export default {
		data() {
			return {
				user: { //提交列表
					id: -1,
					is_end:-1,
					list: [],
					page: 1,
					// 获取列表
					get_data(activit_id, reset,is_end) {
						if (this.id == -1) {
							this.id = activit_id;
						}
						if (this.is_end == -1){
							this.is_end = is_end;
						}
						if (reset) {
							this.list = [];
							this.page = 1;
						}
						if (this.page == -1) {
							return
						}
						$vue.$utils.postrequest('/api/activit_signup/getsignup', {
							activit_id: this.id,
							page: this.page
						}, res => {
							res.data.map(item => {
								item.avatar = JSON.parse(item.avatar);
								item.headImage = item.avatar[0];
								item.created_time = $vue.$utils.get_time(item.created_at);
							})
							this.list = [...this.list, ...res.data];
							this.page++
							if (res.data.length < 1) {
								this.page = -1;
							}
						})
					},
					// 通过
					pass(id){
						if (this.is_end){
							uni.showToast({
								title:"活动已结束",
								icon:"none"
							})
							return
						}
						let data = {
							id
						}
						$vue.$utils.postrequest('/api/activit_signup/signup_pass',data,res =>{
							if (res.code == 200){
								uni.showToast({
									title:"通过成功"
								})
								this.get_data(-1,true);
							}
						});
					},
					wancheng(){
						let data = {
							activit_id:this.id
						}
						$vue.$utils.postrequest('/api/activit_signup/signup_end',data,res=>{
							if(res.code == 200){
								uni.showToast({
									title:res.message
								})
								setTimeout(() => {
									uni.navigateBack();
								}, 1000);
							}else{
								uni.showToast({
									title:res.message,
									icon:"none"
								})
							}
						})
					}
				}
			}
		},
		onLoad(options) {
			$vue = this;
			this.user.get_data(options.id, true,options.is_end);
		},
		onReachBottom() {
			this.user.get_data();
		},
		methods: {
			back() {
				uni.navigateBack();
			},
			// 获取提交列表

		}
	}
</script>

<style scoped lang="scss">
	@import "./submit-list.scss";
</style>
